/******************************************************************************
*  COPYRIGHT MorningCore CO.,LTD
******************************************************************************/

/******************************************************************************
*  INCLUDE FILES
******************************************************************************/
/*****************************************************************
* FileName::    <PUSCH_TransPrecoding.c>
* version::     <1.0.0>
* Purpose:      <do pusch precoding, i.e hybrid radix dft>
* Authors:      <guohuayong, 2008-12-16>
* Notes:        <no>
******************************************************************/

/******************************************************************************
*  HISTORY OF CHANGES
*   <Date>          <Author>        <Version>       <DESCRIPTION>
*   ...             ...              ...            ....
******************************************************************************/

/******************************************************************************
*  INCLUDE FILES

******************************************************************************/
#include "../head/ue_tx_pusch_transprecoding_fix.h"

/*----------- function definition-----------------------------------*/
/*****************************************************************************
* Function: PUSCH_TransPrecoding()
* Purpose:  This function performs Transprecoding processing
*
* Relation:
Calls       : ....
Called by   : ....
* Params:
*   <Name>          <Type>      <In/Out>    <Description>
  Data[12][1320]    cmplx_frN    In/Out     input data and the result is also in this buffer
  PUSCH_RB_Num      int8          In        RB number of PUSCH
  Alpha2            int8          In        exponent of 2
  Alpha3            int8          In        exponent of 3
  Alpha5            int8          In        exponent of 5
  PUSCH_SymNum      int8          In        number of SC-FDMA symbols for PUSCH
  AmpCoef           fractN        In        make the DataIp(modulation output) from Q(4,4) to Q(11,4)
  Radix2Shift[11]   int8          In        shift flag for fft2
  Radix3Shift[5]    int8          In        shift flag for fft3
  Radix5Shift[2]    int8          In        shift flag for fft5
  BitLen            int8          In        fixed data bit length

* Return:  void
* Note:    old name is PUSCHPrecoding,renamed by lixiaojiao for R11 PUSCH Precoding
*******************************************************************************/
void PUSCH_TransPrecoding_fix
(
    INOUT cmplx_frN Data[][PUSCH_Max_RE],
    IN int    PUSCH_RB_Num,
    IN int8   Alpha2,
    IN int8   Alpha3,
    IN int8   Alpha5,
    IN int8   PUSCH_SymNum,
    IN fractN AmpCoef,
    IN int8   Radix2Shift[11],
    IN int8   Radix3Shift[5],
    IN int8   Radix5Shift[2],
    IN int8   BitLen
)
{
    /*variables definition*/
    int16   DFT_Len;
    int16   HybridDFT_Len[3];       //HybridDFT_Len[0] is radix-2's len,HybridDFT_Len[1] is radix-3's len,HybridDFT_Len[2] is radix-5's len
    int16   HybridDFT_Times[3];     //corresponding to each radix times

    int8    i;      //for cycle
    int8    ShiftFlag;

    ShiftFlag = 1;

    /*Function body*/
    HybridDFT_Len[0] = (short)pow(2.0, Alpha2);
    HybridDFT_Len[1] = (short)pow(3.0, Alpha3);
    HybridDFT_Len[2] = (short)pow(5.0, Alpha5);

    HybridDFT_Times[0] = HybridDFT_Len[1] * HybridDFT_Len[2];
    HybridDFT_Times[1] = HybridDFT_Len[0] * HybridDFT_Len[2];
    HybridDFT_Times[2] = HybridDFT_Len[0] * HybridDFT_Len[1];   // calculation some parameter

    DFT_Len = PUSCH_RB_Num * 12;

    for (i = 0; i < PUSCH_SymNum; i++) //PUSCH_SymNum
    {
        HybridDFT_fix(
            Data[i],
            DFT_Len,
            Alpha2,
            Alpha3,
            Alpha5,
            HybridDFT_Len,
            HybridDFT_Times,
            AmpCoef,
            Radix2Shift,
            Radix3Shift,
            Radix5Shift,
            BitLen,
            ShiftFlag       // used for test
        );
    }           // each do one sc_fdma symbol
}




